import Vue from 'vue';
import ElementUI from 'element-ui';
import vm_main from "./layout/vm_main.vue";
import store from './store';
import GeneralToolsCollectionPackageKit from "gtcpk-fe";
import 'element-ui/lib/theme-chalk/index.css';
import './main.css';
import Axios from "axios";

Vue.use(ElementUI);
Vue.prototype.$axios = Axios;
Vue.prototype.$GenTools = new GeneralToolsCollectionPackageKit();
Vue.prototype.$GenTools.DataTypeDetect({
    _GlobalOperate: {
        enableDict: true, bind: {
            String: {aliasVal: "str", aliasDsc: "为字符串类型"},
            Array: {aliasVal: "arr", aliasDsc: "为数组类型"},
            Object: {aliasVal: "obj", aliasDsc: "为对象类型"},
            Boolean: {aliasVal: "boo", aliasDsc: "为布尔类型"},
            Number: {aliasVal: "num", aliasDsc: "为数字类型"},
            Undefined: {aliasVal: "und", aliasDsc: "未知定义类型"},
            Function: {aliasVal: "fun", aliasDsc: "为函数类型"},
            AsyncFunction: {aliasVal: "anf", aliasDsc: "为异步函数类型"},
            Null: {aliasVal: "nul", aliasDsc: "为空数据类型"},
            process: {aliasVal: "pro", aliasDsc: "Node JS Process对象"},
            Promise: {aliasVal: "pme", aliasDsc: "Node JS Promise对象"}
        }, RetValueType: 0
    }
});
Vue.prototype.__$completeBaseInfo = true;
Vue.prototype.__$completeLogoRequest = true;
Vue.prototype.__$lastID = "";
Vue.prototype.__$keepCount = 0;
Vue.prototype.$infoBus = undefined;
Vue.prototype.$TaskStackHandle = undefined;
Vue.prototype.$UpdateData = (curIns, callback) => {
    if (curIns.__$completeBaseInfo) {
        curIns.__$completeBaseInfo = false;
        curIns.$axios(
            {
                url: "/baseInfo",
                method: "post",
                data: {existHost: "all", SupportTech: "all", SupportOperateSystem: "all"}
            }
        ).then((value) => {
            let {data} = value;
            curIns.$store.commit("infoPool/SupportTechOperate", data.SupportTech);
            curIns.$store.commit("infoPool/HostListOperate", data.ExistsHost);
            curIns.$store.commit("infoPool/PhysicalHostDataOperate", data.PhysicalHostInfo);
            curIns.$store.commit("infoPool/OperateSystemListOperate", data.SupportOperateSystem);
            if (typeof callback === 'function') {
                callback(true, value);
            }
            curIns.__$completeBaseInfo = true;
        }).catch((value) => {
            if (typeof callback === 'function') {
                callback(false, value);
            }
            curIns.__$completeBaseInfo = true;
        });
    }
    if (curIns.__$completeLogoRequest) {
        curIns.__$completeLogoRequest = false;
        curIns.$axios.post("/ui_res", {need: ['image', 'logo.png']}).then((vl) => {
            let PageTabIconControl = document.getElementById("PageTabIcon");
            PageTabIconControl.href = vl.data;
            curIns.__$completeLogoRequest = true;
        }).catch((vl) => {
            curIns.__$completeLogoRequest = true;
        });
    }
}
document.title = "QEMU 虚拟机管理软件Web版（QEMU Virtual Machine For Web）";
new Vue({
    store,
    render: (handle) => {
        return handle(vm_main);
    }
}).$mount('#vm_Interface');